package com.itheima.web.controller.sms;

import com.itheima.result.ResultData;
import com.itheima.service.sms.SmsFlashPromotionSessionService;
import com.itheima.vo.sms.SmsFlashPromotionSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动场次
 */
@RestController
@RequestMapping("/flashSession")
@Slf4j
public class SmsFlashPromotionSessionController {

    @DubboReference
    private SmsFlashPromotionSessionService service;

    /**
     * 添加场次
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("create")
    public ResultData create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        log.info("添加场次信息：{}",smsFlashPromotionSession);
        int result =service.create(smsFlashPromotionSession);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 删除场次
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResultData delete(@PathVariable Long id){
        log.info("删除场次ID：{}",id);
        int result =service.delete(id);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 获取全部场次
     * @return
     */
    @GetMapping("list")
    public ResultData list(){
        List<SmsFlashPromotionSession> list=service.selectAll();
        return ResultData.ok("操作成功",list);
    }

    /**
     * 获取全部可选场次及其数量
     * @param flashPromotionId
     * @return
     */
    @GetMapping("selectList")
    public ResultData selectList(Long flashPromotionId){
        List<SmsFlashPromotionSession> list=service.selectList(flashPromotionId);
        return ResultData.ok("操作成功",list);
    }

    /**
     * 修改启用状态
     * @param id
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping ("/update/status/{id}")
    public ResultData updateStatus(@PathVariable Long id, SmsFlashPromotionSession smsFlashPromotionSession){
        log.info("修改上下线状态:{},{}",id,smsFlashPromotionSession);
        int result=service.updateStatus(id,smsFlashPromotionSession);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 修改场次
     * @param id
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("update/{id}")
    public ResultData updateFlashPromotion(@PathVariable Long id,@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        log.info("修改上下线状态:{},{}",id,smsFlashPromotionSession);
        int result=service.updateFlashPromotion(id,smsFlashPromotionSession);
        return ResultData.ok("操作成功",result);
    }

    /**
     * 获取场次详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResultData selectById(@PathVariable Long id){
        log.info("查询活动详情的id：{}",id);
        SmsFlashPromotionSession smsFlashPromotionSession=service.selectById(id);
        return ResultData.ok("操作成功",smsFlashPromotionSession);
    }

}
